home *** CD-ROM | disk | FTP | other *** search
- {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- (c) TechInsite Pty. Ltd.
- PO Box 429, Abbotsford, Melbourne. 3067 Australia
- Phone: +61 3 9419 6456
- Fax: +61 3 9419 1682
- Web: www.techinsite.com.au
- EMail: peter_hinrichsen@techinsite.com.au
-
- Created: October 1999
-
- Notes: Show the subject as a bar graph
-
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
- unit FObserver_BarGraph;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, TeEngine, Series, ExtCtrls, TeeProcs, Chart,
- FObserver_Abstract;
-
- type
-
- //--------------------------------------------------------
- TFormObserverBarGraph = class(TFormObserverAbstract)
- Chart1: TChart;
- Series1: TBarSeries;
- procedure FormCreate(Sender: TObject);
- private
- // Get a unique colour to show in the graph
- function GetColour( const pI : integer ) : TColor ;
- public
- // Override the virtual abstract DataToObserver method
- procedure DataToObserver ; override ;
- end;
-
- implementation
- uses
- // To give access to the TStockTrans so
- // we can access data in the subject
- Subject_Portfolio
- ;
-
- {$R *.DFM}
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TFormViewBarGraph
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- procedure TFormObserverBarGraph.DataToObserver ;
- var
- i : integer ;
- lStockTrans : TStockTrans ;
- begin
- chart1.series[0].clear ;
- with Subject as TPortfolio do begin
- for i := 0 to Stocks.Count - 1 do begin
- lStockTrans := Stocks.Items[ i ] ;
- chart1.series[0].add( lStockTrans.Value,
- lStockTrans.StockCode,
- GetColour( i )) ;
- end ;
- end ;
- end;
-
- //----------------------------------------------------------
- procedure TFormObserverBarGraph.FormCreate(Sender: TObject);
- begin
- inherited;
- // Save a pointer into the subject
- Subject := gPortfolio ;
- end;
-
- // Get a unique colour to display in the graph
- //----------------------------------------------------------
- function TFormObserverBarGraph.GetColour(const pI:
- integer): TColor;
- begin
- case pI of
- 0 : result := clRed ;
- 1 : result := clBlue ;
- 2 : result := clGreen ;
- 3 : result := clYellow ;
- 4 : result := clAqua ;
- else
- result := clBlack ;
- end ;
- end;
-
- end.
-
-